package com.shengruan.admin.action;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.shengruan.admin.jdbc.PayParameterJdbc;
import com.shengruan.admin.vo.PayParameter;
import com.shengruan.common.BaseAction;
import com.shengruan.common.Constants;

public class PayParameterAction extends BaseAction {

    Logger logger = LoggerFactory.getLogger(getClass());
    private PayParameterJdbc payParameterJdbc = (PayParameterJdbc) this.getJdbc(PayParameterJdbc.class);

    public void list() throws Exception {
        List<PayParameter> payParameterList = this.payParameterJdbc.findAll();
        this.setRequest("payParameterList", payParameterList);
        this.forward("/admin/article/payParameter-list.jsp");
    }


    /**
     * 添加商品
     *
     * @throws Exception
     */
    public void add() throws Exception {
        String bidding = this.input("bidding");
        String giftBidding = this.input("giftBidding");
        String amount = this.input("amount");

        PayParameter payParameter = new PayParameter();
        payParameter.setBidding(Integer.valueOf(bidding));
        payParameter.setGiftBidding(Integer.valueOf(giftBidding));
        payParameter.setAmount(Double.valueOf(amount));
        payParameter.setCreationTime(System.currentTimeMillis());
        this.payParameterJdbc.save(payParameter);

        this.setRequest(Constants.MESSAGE, "添加支付参数成功。");
        this.redirect("/admin/article/payParameter-list.ac");
    }

    public void getById() throws Exception {
        String id = this.input("id");
        PayParameter payParameter = this.payParameterJdbc.getById(Integer.valueOf(id));

        this.setRequest("payParameter", payParameter);
        this.forward("/admin/article/payParameter-edit.jsp");
    }

    public void edit() throws Exception {
        String id = this.input("id");
        String bidding = this.input("bidding");
        String giftBidding = this.input("giftBidding");
        String amount = this.input("amount");

        PayParameter payParameter = this.payParameterJdbc.getById(Integer.valueOf(id));
        payParameter.setBidding(Integer.valueOf(bidding));
        payParameter.setGiftBidding(Integer.valueOf(giftBidding));
        payParameter.setAmount(Double.valueOf(amount));

        this.payParameterJdbc.update(payParameter);


        this.setRequest(Constants.MESSAGE, "修改支付参数成功。");
        this.redirect("/admin/article/payParameter-list.ac");
    }

    public void delete() throws Exception {
        String id = this.input("id");

        this.payParameterJdbc.deleteById(Integer.valueOf(id));
        this.setRequest(Constants.MESSAGE, "删除支付参数成功。");
        this.redirect("/admin/article/payParameter-list.ac");
    }
}
